package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description: 逐行读取数据
 * @author: 化一帆
 * @date: 2022/11/24 14:42
 * @version: v1.0
 */
@Component
public class DictListener extends AnalysisEventListener<DictEeVo> {
    @Autowired
    private DictMapper dictMapper;
    //一行一行的进行读取
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //调用方法将数据添加进数据库
        Dict dict = new Dict();

        //将读取到的每行的dictEeVo对象中的数据复制到Dict对象中
        BeanUtils.copyProperties(dictEeVo,dict);

        //将读取到的对象存入数据库
        dictMapper.insert(dict);
    }

    /**
     * @description:  所有的行在读取完之后调用一次
     * @author 化一帆
     * @date 2022/12/2 10:26
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
